package demoMod.gdxform.interfaces;

import com.badlogic.gdx.graphics.Color;

/**
 * 具有边框属性的元素
 */
public interface Border extends Element {
    float getBorderWidth();

    void setBorderWidth(float borderWidth);

    Color getBorder();

    void setBorder(Color border);

    /**
     * 判断指定位置是否在此边框上
     * @param x 横坐标
     * @param y 纵坐标
     * @return 如果指定位置在此边框上，返回<code>true</code>；否则返回<code>false</code>
     */
    default boolean atBorder(float x, float y) {
        if (getBorderWidth() == 0) return false;
        float startX1 = getX(true) - getBorderWidth();
        float endX1 = getX(true);
        float startX2 = getX(true) + getWidth();
        float endX2 = getX(true) + getWidth() + getBorderWidth();

        float startY1 = getY(true) - getBorderWidth();
        float endY1 = getY(true);
        float startY2 = getY(true) + getHeight();
        float endY2 = getY(true) + getHeight() + getBorderWidth();

        return (x >= startX1 && x <= endX1 && y >= startY1 && y <= endY2) ||
                (x >= startX1 && x <= endX2 && y >= startY2 && y <= endY2) ||
                (x >= startX2 && x <= endX2 && y >= startY1 && y <= endY2) ||
                (x >= startX1 && x <= endX2 && y >= startY1 && y <= endY1);
    }
}
